#   Copyright (c)  鱼肠的渔场小组  2025-2025 . All rights reserved.
#   TradingPlatform_Server is licensed under Mulan PSL v2.
#   You can use this software according to the terms and conditions of the Mulan
#   PSL v2.
#   You may obtain a copy of Mulan PSL v2 at:
#            http://license.coscl.org.cn/MulanPSL2
#   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
#   KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
#   NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#   See the Mulan PSL v2 for more details.

import requests
import hashlib


def test_auth_login():
    #用户登录
    url = "http://10.153.6.232:8080/auth/login"
    pwd = "2842069969Liuzian"
    hash_pwd = hashlib.md5(pwd.encode('utf-8')).hexdigest()
    data = {
        "phone": "15295976257",
        "password": hash_pwd
    }
    response = requests.post(url, data=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

    data = {
        "phone": "18477344490",
        "password": "<PASSWORD>"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

    data = {
        "phone": "15295996357",
        "password": "123456"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_takeout_name():
    #查询当前名称外卖信息
    url = "http://10.153.6.232:8080/takeout/takeout-name"
    data = {
        "name": "1"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None


def test_user_register():
    #用户注册
    url = "http://10.153.6.232:8080/user/user"
    pwd = "111"
    hash_pwd = hashlib.md5(pwd.encode('utf-8')).hexdigest()
    data = {
        "username": "清明雨揽月",
        "password": pwd,
        "phone": "111"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_user_info():
    #查询用户信息
    url = "http://10.153.6.232:8080/user/user"
    data={
        "id":"0f88dfc4-8f56-11ef-ad59-e86f389cc271"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_takeout_query():
    #查询单个外卖
    url = "http://10.153.6.232:8080/takeout/takeout"
    data = {
        "takeout_id": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_takeout_kind():
    #按种类查询外卖
    url = "http://10.153.6.232:8080/takeout/takeout-kind"
    data = {
        "kind": "1"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_takeout_queryall():
    #查询所有外卖
    url = "http://10.153.6.232:8080/takeout/takeout-all"
    response = requests.get(url)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_takeout_on():
    #外卖上架申请
    url = "http://10.153.6.232:8080/takeout/takeout"
    data = {
        "username": "test",
        "password": "test5678",
        "phone": "111"
    }
    response = requests.post(url,data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_payment():
    #支付请求
    url = "http://10.153.6.232:8080/payment/payment"
    data = {
        "price": "100",
        "payment_method": "weixin",
        "order_id": "001",
        "user_id": "test",
        "store_id": "store"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_order_create():
    #生成当前订单
    url = "http://10.153.6.232:8080/order/order"
    data = {
        "price": "100",
        "count": "1",
        "payment_method": "weixin",
        "note": "123",
        "address_id": "beijing",
        "user_id": "test",
        "store_id": "store"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_order_queryall():
    #获取所有订单
    url = "http://10.153.6.232:8080/order/query-all"
    response = requests.get(url)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_order_delete():
    #取消当前订单
    url = "http://10.153.6.232:8080/order/order"
    data = {
        "uuid": "0001"
    }
    response = requests.delete(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_order_query():
    #获取单个订单
    url = "http://10.153.6.232:8080/order/order"
    data = {
        "uuid": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_order_update():
    #签收订单
    url = "http://10.153.6.232:8080/order/order"
    data = {
        "uuid": "001"
    }
    response = requests.update(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_delivery_query():
    #获取单个订单配送信息
    url = "http://10.153.6.232:8080/delivery/query-one"
    data = {
        "uuid": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_store_request():
    #申请店铺
    url = "http://10.153.6.232:8080/store"
    data = {
        "store_name": "abc",
        "owner": "123"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_store_delete():
    #关闭店铺
    url = "http://10.153.6.232:8080/store"
    data = {
        "store_id": "001",
    }
    response = requests.delete(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_store_update():
    #店铺信息修改
    url = "http://10.153.6.232:8080/store"
    data = {
        "store_id": "001",
        "new_store_name": "abc"
    }
    response = requests.update(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_store_query():
    #获取店铺信息
    url = "http://10.153.6.232:8080/store"
    data = {
        "store_id": "001",
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_audit_store():
    #店铺申请审核
    url = "http://10.153.6.232:8080/audit/audit-store"
    data = {
        "store_id": "001",
        "resole_or_reject": "1"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_audit_takeout():
    #外卖上架申请审核
    url = "http://10.153.6.232:8080/audit/audit-takeout"
    data = {
        "takeout_id": "001",
        "resole_or_reject": "1"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_address_create():
    #创建地址
    url = "http://10.153.6.232:8080/address"
    data = {
        "user_id": "001",
        "school_name": "abc",
        "campus": "111",
        "address": "123456"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_address_delete():
    #删除地址
    url = "http://10.153.6.232:8080/address"
    data = {
        "id": "001"
    }
    response = requests.delete(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_address_queryall():
    #获取用户所有地址
    url = "http://10.153.6.232:8080/address"
    data = {
        "user_id": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_discuss_queryall():
    #获取外卖所有评论
    url = "http://10.153.6.232:8080/discuss"
    data = {
        "takeout_id": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_discuss_create():
    #发表评论
    url = "http://10.153.6.232:8080/discuss"
    data = {
        "content": "1111111",
        "user_id": "001",
        "takeout_id": "001"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_discuss_delete():
    #删除评论
    url = "http://10.153.6.232:8080/discuss"
    data = {
        "discuss_id": "001"
    }
    response = requests.delete(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_menu_create():
    #加入菜单
    url = "http://10.153.6.232:8080/menu"
    data = {
        "id": "001"
    }
    response = requests.post(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_menu_delete():
    #移除菜单
    url = "http://10.153.6.232:8080/menu"
    data = {
        "id": "001"
    }
    response = requests.delete(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None

def test_menu_query():
    #查询菜单
    url = "http://10.153.6.232:8080/menu"
    data = {
        "id": "001"
    }
    response = requests.get(url, json=data)
    print("\nCode:{}".format(response.status_code))
    print("Json:{}".format(response.json()))
    assert response.status_code == 200
    assert response.json() is not None